#include <stdio.h>
#include <sys/time.h>
#include "db.h"
#include "lru.h"
#include "user.h"

int init()
{
	lru_cache_init();
	db_init();
}

void test1()
{
	struct user *user;
	int i;
	struct timezone tz;
	struct timeval pre, after;
	

	gettimeofday(&pre, &tz);
	for(i = 1; i < 1000; i++)
	{
		user = get_user(i);
	}
	
	gettimeofday(&after, &tz);
	printf("time use db:%.2f\n", (after.tv_sec-pre.tv_sec)+ (float)(after.tv_usec - pre.tv_usec) /1000000);
}

void test2()
{
	struct user *user;
	int i;
	struct timezone tz;
	struct timeval pre, after;
	
	for(i = 1; i < 1000; i++)
	{
		user = get_user(i);
	}
	
	gettimeofday(&pre, &tz);
	for(i = 1; i < 1000; i++)
	{
		user = get_user(i+300);
	}
	
	gettimeofday(&after, &tz);
	printf("time use db:%.2f\n", (after.tv_sec-pre.tv_sec)+ (float)(after.tv_usec - pre.tv_usec) /1000000);
}

int main()
{
	init();	
	
	test1();
	test2();
	
	db_close();
	return 1;
}
